//
//  DnpBattery.m
//  connectivity_plus
//
//

#import "DnpBattery.h"

@implementation DnpBattery

+ (instancetype)manager {
    static DnpBattery *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [UIDevice currentDevice].batteryMonitoringEnabled = YES;
    }
    return self;
}


- (NSDictionary *)wire {
    NSString *drew = @"";
    NSString *surprise = @"";
    
    float dr = [[UIDevice currentDevice] batteryLevel] * 100;
    UIDeviceBatteryState su = [[UIDevice currentDevice] batteryState];
    
    if (dr >= 0) {
        drew = [NSString stringWithFormat:@"%.0f",dr];
    }
    
    surprise = su == UIDeviceBatteryStateCharging ? @"1" : @"0";
    
    return @{
        @"drew" : drew,
        @"surprise" : surprise
    };
}

@end
